# Build Stage
FROM whello/golang-builder:alpine AS build-stage

LABEL app="build-shippy-forestage"
LABEL REPO="https://gitee.com/whello/shippy-forestage"

ENV PROJPATH=/go/src/gitee.com/whello/shippy-forestage

# Because of https://github.com/docker/docker/issues/14914
ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin

ADD . /go/src/gitee.com/whello/shippy-forestage
WORKDIR /go/src/gitee.com/whello/shippy-forestage

RUN make build-alpine

# Final Stage
FROM golang:alpine

ARG GIT_COMMIT
ARG VERSION
LABEL REPO="https://gitee.com/whello/shippy-forestage"
LABEL GIT_COMMIT=$GIT_COMMIT
LABEL VERSION=$VERSION

# Because of https://github.com/docker/docker/issues/14914
ENV PATH=$PATH:/opt/shippy-forestage/bin

WORKDIR /opt/shippy-forestage/bin

COPY --from=build-stage /go/src/gitee.com/whello/shippy-forestage/bin/shippy-forestage /opt/shippy-forestage/bin/
RUN chmod +x /opt/shippy-forestage/bin/shippy-forestage

# Create appuser
RUN adduser -D -g '' shippy-forestage
USER shippy-forestage

ENTRYPOINT ["/usr/bin/dumb-init", "--"]

CMD ["/opt/shippy-forestage/bin/shippy-forestage"]
